package com.ericscode.html5.example.websocket.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ericscode.html5.example.websocket.server.WebchatServer;


@Path("/ws")
public class WebsocketResource {

	private static final Logger logger = LoggerFactory.getLogger(Logger.class);
	
	
	@GET
	public String test() {
		return "test";
	}
	
	@GET
	@Path("/server/{port}")
	public String startServer(@PathParam("port") int port) {
		logger.info("start a server on port =" + port);
		
		WebchatServer server = WebchatServer.startServer(port);
		
		return "successfully started Webchat server on port = " + port + " server = " + server;
	}
	
	@GET
	@Path("/server/stop/{port}")
	public String stopServer(@PathParam("port") int port) {
		logger.info("stop a server on port = " + port);
		
		//WebchatServer.stopServer(null);
		
		return "sucessfully stopped Webchat server on port = " + port;
	}
	
}
